<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="author" content="lzy">
    <title>lzy-</title>
    <script src="jquery-3.1.1.js"></script>
    <style>
        ul,li{
            margin: 0;
            padding: 0;
            list-style: none;
        }
        .content{
            width: 520px;
            height: 280px;
            margin: 100px auto;
            position: relative;
        }
        .content .pic li{
            position: absolute;
            top: 0;
            left: 0;
            display: none;
        }
        .content .pic li.current{
            display: block;
        }
        .content .indicator{
            position: absolute;
            left: 5px;
            bottom: 5px;
        }
        .content .indicator li{
            float: left;
            width: 20px;
            height: 20px;
            background-color: greenyellow;
            margin: 5px;
            line-height: 20px;
            text-align: center;
            color: orange;
            cursor: pointer;
        }
        .content .indicator li.active{
            background-color: purple;
        }
        .content .page{
            position: absolute;
            right: 10px;
            bottom: 10px;
            color: blue;
        }
        .content .page span{
            display: inline-block;
            width: 30px;
            height: 30px;
            background-color: rgba(0,0,0,0.3);
            font-size: 30px;
            line-height: 30px;
            text-align: center;
            cursor: pointer;
        }
        .content .page span:hover{
            background-color: rgba(0,0,0,0.5);
        }
    </style>
</head>
<body>
    <div class="content">
        <ul class="pic">
            <li class="current"><a href="#"><img src="images/01.jpg" alt=""></a></li>
            <li><a href="#"><img src="images/02.jpg" alt=""></a></li>
            <li><a href="#"><img src="images/03.jpg" alt=""></a></li>
            <li><a href="#"><img src="images/04.jpg" alt=""></a></li>
            <li><a href="#"><img src="images/05.jpg" alt=""></a></li>
        </ul>
        <!--指示灯-->
        <ul class="indicator">
            <li class="active">1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
            <li>5</li>
        </ul>
        <!--左右按钮-->
        <div class="page">
            <span class="prev">&lt;</span>
            <span class="next">&gt;</span>
        </div>
    </div>
</body>
</html>
<script>
    // 图片的索引值，初始是0 第一张图
    var index = 0;

    // 1.自动切换
    var timer =setInterval(nextImg,1000);
    // 下一张图
    function nextImg(){
        index = index==$('.pic li').length-1 ? 0: index+1;
        showImg();
    }
    // 上一张
    function prevImg(){
        index = index==0 ? $('.pic li').length-1 : index-1;
        showImg();
    }
    // 展示图片和指示灯
    function showImg(){
        // 根据索引值，显示当前图片，隐藏其他图片
        $('.pic li').eq(index).show().siblings().hide();
        $('.indicator li').eq(index).addClass('active').siblings().removeClass('active');
    }
    // 2.悬停切换
    $('.indicator li').hover(function(){
        // 鼠标进入指示灯，停止自动切换
        clearInterval(timer);
        index=$(this).index();
        showImg();
    },function(){
        // 鼠标出来，恢复自动切换
        timer=setInterval(nextImg,1000);
    })
    // 3.点击按钮切换
    $('.content .page span').hover(function(){
        clearInterval(timer);
        // 上一张
        $('.page .prev').click(function(){
            prevImg();
        })

        // 下一张
        $('.page .next').click(function(){
            nextImg();
        })
    },function(){
        timer=setInterval(nextImg,1000);
    });
</script>